<?php

require_once 'plugin/DBPlugin.php';

/**
 * Manejo de las obras anteriores.
 */
class ObrasDBPlugin extends DBPlugin {

	

	/**
	 * Obtener todas las obras anteriores
	 */	
	public static function getObrasPublished() {

		require_once ('include/connect.php');
		
		$sql = "SELECT * FROM `obras`";
		$sql .= " WHERE published = 1";
		$results = mysql_query($sql);

		$obras = array();
		while($obra = mysql_fetch_assoc($results)) {
			$obras[] = $obra;
		}
		
		return $obras;
	
	}
	

	/**
	 * Obtener todas las obras por tipo
	 */	
	public static function getObrasPublishedByType($type) {

		require_once ('include/connect.php');
		
		$sql = "SELECT * FROM `obras`";
		$sql .= " WHERE published = 1";
		$sql .= " AND tipoobra = '" . $type ."'";
		$results = mysql_query($sql);

		$obras = array();
		while($obra = mysql_fetch_assoc($results)) {
			$obras[] = $obra;
		}
		
		return $obras;
	
	}
	
	
	/**
	 * Obtener una obra por id
	 */	
	public static function getById($id) {

		require_once ('include/connect.php');
		
		$sql = "SELECT * FROM `obras` where idobra = ".$id;
		//exit;
		$result = mysql_query($sql);
		$num = mysql_num_rows($result);
		if ($num > 0) {
			$row = mysql_fetch_array($result);
			return $row;
		}
		return null;
	
	}

	
	
	/**
	 * Obtiene las imagenes de una obra
	 */
	public static function getImages($idObra, $imagetype) {

		require_once ('include/connect.php');
	
		$sql = "select * from `images`".
		 		" where tablename = 'obras'".
				" and iditem = ".$idObra.
				" and imagetype = '".$imagetype."'";
		$results = mysql_query($sql);
		
		$fotos = array();
		while($foto = mysql_fetch_assoc($results)) {
			$fotos[] = $foto;
		}
		
		return $fotos;
	}
	
}

?>